<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#inputForm").validate({
				rules: {
					loginName: {remote: "${ctxAdmin}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${user.loginName}')}
				},
				messages: {
					loginName: {remote: "用户登录名已存在"},
					confirmNewPassword: {equalTo: "输入与上面相同的密码"}
				},
				submitHandler: function(form){
					ajaxForm(form);
				},
				errorClass: 'validation-invalid-label',
				highlight: function(element, errorClass) {
					$(element).removeClass(errorClass);
				},
				errorPlacement: function (error, element) {
					validateErrorPlacement(error, element);
				}
			});
		});
	</script>
</head>
<body>
<div class="content">
	<div class="card">
		<div class="card-body">
			<form:form id="inputForm" method="post"
					   modelAttribute="user" action="${ctxAdmin}/sys/user/save4Role" >
				<form:hidden path="id"/>
				<input type="hidden" name="company.id" value="${fns:getUser().company.id}">
				<input type="hidden" name="loginFlag" value="1">
				<sys:message content="${message}"/>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">归属公司:</label>
					<div class="col-sm-9">
						<input type="text" readonly value="${user.company.name}" class="form-control">
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">归属部门:</label>
					<div class="col-sm-9">
						<sys:treeselect id="office" name="office.id" value="${user.office.id}" labelName="office.name" labelValue="${user.office.name}"
							title="部门" url="/sys/office/treeData?type=2" cssClass="required" notAllowSelectParent="true"/>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">用户姓名:</label>
					<div class="col-sm-9">
						<form:input path="name" htmlEscape="false" maxlength="50" cssClass="form-control required"/>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">登录账号:</label>
					<div class="col-sm-9">
						<input id="oldLoginName" name="oldLoginName" type="hidden" value="${user.loginName}">
						<form:input path="loginName" htmlEscape="false" maxlength="50" cssClass="form-control required userName"/>
					</div>
				</div>

				<div class="form-group row">
					<label class="col-sm-3 col-form-label">证件类型:</label>
					<div class="col-sm-9">
						<form:select path="credentialType" class="form-control required">
							<form:options items="${fns:getDictList('credential_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">证件编号:</label>
					<div class="col-sm-9">
						<form:input path="credentialNo" htmlEscape="false" maxlength="100" cssClass="form-control required"/>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">用户性别:</label>
					<div class="col-sm-9">
						<form:select path="sex" class="form-control required">
							<form:options items="${fns:getDictList('sex')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">电子邮箱:</label>
					<div class="col-sm-9">
						<form:input path="email" htmlEscape="false" maxlength="100" cssClass="form-control required email"/>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">手机号码:</label>
					<div class="col-sm-9">
						<form:input path="mobile" htmlEscape="false" maxlength="100" cssClass="form-control required"/>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">固定电话:</label>
					<div class="col-sm-9">
						<form:input path="phone" htmlEscape="false" maxlength="100" cssClass="form-control"/>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-sm-3 col-form-label">用户类型:</label>
					<div class="col-sm-9">
						<select name="userType" class="multiselect form-control" multiple="multiple">
						<c:forEach items="${fns:getDictList('sys_user_type')}" var="dict" >
							<option value="${dict.value}" ${fn:contains(user.userType,dict.value) ? 'selected':''}>${dict.label}</option>
						</c:forEach>
						</select>
					</div>
				</div>
				<div class="form-group row mb-0">
					<div class="col-sm-9 ml-sm-auto">
						<shiro:hasPermission name="sys:user:edit">
							<button type="submit" class="btn btn-primary"><i class="icon-database-check mr-2"></i>保 存</button>
						</shiro:hasPermission>
						<button type="button" class="btn btn-light" onclick="cancelSelect()" ><i class="icon-database-arrow mr-2"></i>取 消</button>
					</div>
				</div>
			</form:form>
		</div>
	</div>
</div>
</body>
</html>